package com.mx.zb.md.tenant.control;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mx.zb.md.tenant.bo.Operator;
import com.mx.zb.md.tenant.bo.Person;
import com.mx.zb.md.tenant.dao.OperatorMapper;
import com.mx.zb.md.tenant.utils.ex.PageAnnotation;

@Controller
@PageAnnotation
public class ThymeleafDemoCtrl {
	
	@Autowired
	OperatorMapper operatorMapper;
	
	@RequestMapping("/")
	public String toLogin() {
		return "login";
	}
	
	@RequestMapping("/login")
	public String login(Operator o, Model model) {
		if(StringUtils.hasText(o.getName()) && StringUtils.hasText(o.getPassword())) {
			int count=operatorMapper.getCount(o);
			if(count==1) {
				return "dashboard";
			}
		}
		model.addAttribute("msg","您输入的用户名或者密码错误");
		return "login";
	}

	@RequestMapping("/demo")
	public String index(Model model) {
		Person single = new Person("aa", 11);
		
		List<Person> people = new ArrayList<Person>();
		Person p1 = new Person("xx", 11);
		Person p2 = new Person("yy",22);
		Person p3 = new Person("zz",33);
		people.add(p1);
		people.add(p2);
		people.add(p3);
		
		model.addAttribute("singlePerson",single);
		model.addAttribute("people", people);
		
		return "demo";
	}
	
}
